class Solution14 {

    int[] memo = new int[31];

    public int fib(int n) {
        //初始化
        for(int i = 0; i < 31; i++){
            memo[i] = -1;
        }
        return dfs(n);
    }

    public int dfs(int n){
        //在备忘录中查找
        if(memo[n] != -1){
            return memo[n];
        }

        if(n == 0 || n == 1) {
            memo[n] = n;  //返回前放回备忘录
            return n;
        }

        memo[n] = dfs(n - 1) + dfs(n - 2);  //返回前放回备忘录
        return memo[n];
    }
}